var app = getApp();
var address = app.globalData.address;
var util = require('../../utils/util.js');
var that;
Page({
  data: {

    hadImg:true,//判断企业简介中是否有拖入图片，有就显示，反之则隐藏，暂时demo默认为展示
    hadProImg: true,//判断产品介绍中是否有拖入图片，有就显示，反之则隐藏，暂时demo默认为展示
    mapStatus:0,
    load:true,
    interval:5000,//切换间隔时间长
    autoplay:true,//是否自动切换
    indicatorDots:true,//是否显示指示点
    duration:1000,//滑动动画时长
  },
  /*拨打电话 */
  indexLinkMe: function () {
    wx.makePhoneCall({
      phoneNumber: that.data.list.relation.content,
    })
  },
  /*点击地址显示隐藏地图 */
  indexapMap: function () {
    if (this.data.mapStatus == 0) {
      let list = that.data.list;
      let latitude = parseFloat(list.latitude.latitude);
      let longitude = parseFloat(list.latitude.longitude);
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        name: list.address.content,
        scale: 28
      })
      // this.setData({
      //   condition: true,
      //   mapStatus: '1'
      // })
    } else {
      this.setData({
        condition: false,
        mapStatus: '0'
      })
    }

  },
  informationJump: function (e) {
    let informationId = e.currentTarget.dataset.informationid;
    wx.navigateTo({
      url: 'subPackages/consulting/consulting?list=' + JSON.stringify(that.data.list),
      //url: '../zixun/index'
    })
  },
  /**
 * 生命周期函数--监听页面初次渲染完成
 */
  onReady: function () {
    //获得dialog组件
    this.dialog = this.selectComponent("#dialog");
  },
  onLoad:function(options){
    that = this;
   
    app.getUserInfo(function (r) {
      // that.showList();
    })

    // that.getSystem();
  },
  onShow: function () {
    if (wx.getStorageSync('check') || wx.getStorageSync('count2') == 0) {

      wx.setStorageSync('count2', 1);
      wx.setStorageSync('check', false);
      that.showList();
    }
  },
  // 点击最后的按钮提示版本
  btnLast: function () {
    wx.showModal({
      title: '',
      content: '版本号v.1.2.1',
      showCancel: false,//是否显示取消按钮
      confirmText: "我知道了",
      success: function (res) {
        if (res.confirm) {
          console.log('点击了我知道了')
        }
      }
    })
  },

  // 网页加载即获取官网数据
  showList:function(){
    that = this;
    let url = address + 'Deploy/toWebsite';
    let params = {
      companyId: wx.getStorageSync('companyId'),
      businessId:wx.getStorageSync('bId')
    };
    let sessionId = app.globalData.sessionId;
    util.headLoading(url, params, '正在加载中',sessionId,function(res){
      console.log(res)
      if(res){
        wx.setStorageSync('toWebsiteCache', res)
        var list = res;
        that.viewShowList(list);
      }    
      //wx.setStorageSync('phoneNumber', list.relation.content);
     
    },function(){
     // var list =  wx.getStorageSync('toWebsiteCache')
      //that.viewShowList(list);
    });
  },
  viewShowList: function (list){
    let marker = [];
    let markers = {};
    markers.id = 0;
    //console.log(list)
    if (list.latitude.latitude) {
      markers.latitude = list.latitude.latitude;
    } else {
      markers.latitude = 23.0212672855;
    }
    if (list.latitude.longitude) {
      markers.longitude = list.latitude.longitude;
    } else {
      markers.longitude = 113.7520460992;
    }
    markers.iconPath = '/icon/carte/map.png';
    markers.width = 35;
    markers.height = 35;
    marker.push(markers)
    that.setData({
      list: list,
      longitude: list.latitude.longitude,
      latitude: list.latitude.latitude,
      markers: marker
    })
  },
  // getPhoneNumber: function (e) {
  //   console.log(e)
  //   if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  //     wx.showModal({
  //       title: '提示',
  //       showCancel: false,
  //       content: '手机号码未授权',
  //       success: function (res) {
  //         wx.navigateTo({
  //           url: '../mall/subPackages/chat/chat',
  //         })
  //       }
  //     })
  //   } else {
  //     that.mobileDecode(e.detail.iv, e.detail.encryptedData);//破解手机号码
  //   }
  //   let url = address + 'Interaction/chat';
  //   let params = { businessId: wx.getStorageSync('bId') };
  //   let sessionId = app.globalData.sessionId;
  //   util.nomeRequest(url, params, sessionId, function (res) {
  //     if (res == 1) {
  //       console.log('记录用户打开聊天成功！')
  //     }
  //   }, function () { });
  // },
  // // 破解手机号码
  // mobileDecode: function (iv, encryptedData) {
  //   let url = address + 'Tool/mobileDecode';
  //   let params = {
  //     openId: wx.getStorageSync('openId'),
  //     sessionKey: wx.getStorageSync('sessionKey'),
  //     encryptedData: encryptedData,
  //     iv: iv,
  //   };
  //   util.request(url, params, function (res) {
  //     app.globalData.phone = res;
  //     wx.setStorageSync('phone', res)
  //     wx.navigateTo({
  //       url: '../mall/subPackages/chat/chat',
  //     })
  //   }, function () { });

  // },
  // toChat: function () {
  //   wx.navigateTo({
  //     url: '../mall/subPackages/chat/chat',
  //   })
  // },

  // testSubmit: function (e) {
  //   util.testSubmit(e);
  // },

  // 获取屏幕宽高
  // getSystem: function () {
  //   wx.getSystemInfo({
  //     success: function (res) {
  //       // console.log(res)
  //       that.setData({
  //         windowHeight: res.windowHeight,
  //         windowWidth: res.windowWidth
  //       })
  //       console.log(that.data.windowHeight)
  //       console.log(that.data.windowWidth)
  //     }
  //   })
  // },
  

})